<script>
	import {
		mapMutations,mapState 
	} from 'vuex'
	import {
		version
	} from './package.json'
	
	// #ifdef APP
	import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
	// #endif
	
	export default {
		onLaunch: function() {
			const that=this
			// #ifdef H5
			console.log(
				`%c hello uniapp %c v${version} `,
				'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px;  color: #fff',
				'background:#007aff ;padding: 1px; border-radius: 0 3px 3px 0;  color: #fff; font-weight: bold;'
			)
			// #endif
			// 线上示例使用
			// console.log('%c uni-app官方团队诚邀优秀前 端工程师加盟，一起打造更卓越的uni-app & uniCloud，欢迎投递简历到 hr2013@dcloud.io', 'color: red');
			console.log('App Launch');
			
			
			
			uni.getStorage({
				   key: 'rember',
				   success: function (res) {
					   
					   if(res.data){
						   uni.getStorage({
							   key: 'userinfo',
							   success: function (res_userinfo) {
								  
								  var userinfo=JSON.parse(res_userinfo.data)	
													  
								  uni.request({
								  	url:that.$store.state.baseUrl+"/system/passport/power",
									method:'POST',
								  	data:{
								  			id:userinfo.id,
								  			remember:res.data,
								  	},
								  	success: (res) => {	
								  			if (res.data.success) {										
								  				
								  				uni.setStorage({
								  					key: 'userinfo',
								  					data: JSON.stringify(res.data.userinfo),
								  					success: function() {
								  						
														that.setUserinfo(res.data.userinfo);
														that.setUserPower(res.data.user_power);
														
								  						
								  					},
								  				
								  				});
								  			} else{
								  				
								  				uni.showToast({
								  									title: "没有数据"+res.data.msg,
								  									icon: 'none'
								  								})
								  			}
								  			
								  	},
								  	fail: (res) => {
								  		   console.log('错误',res) 
								  		   
								  			uni.showToast({
								  								title: "加载失败,服务器错误",
								  								icon: 'none'
								  							})
								  			
								  	}
								  	
								  		
								  });
								   
							   },
							   fail:function (res_userinfo) {
									console.log('fail',res_userinfo);
									//找不到缓存，跳转到登录界面
									uni.reLaunch({
										url: '/pages/login/login'
									});
							   	
							   },
						   })
					   }else{
						   //未保存缓存，跳转到登录界面
						   uni.reLaunch({
						   	url: '/pages/login/login'
						   });
					   }
										
						
					
					
					},
					fail:function (res) {
						console.log('fail',res);
						//找不到缓存，跳转到登录界面
						uni.reLaunch({
							url: '/pages/login/login'
						});
						
					},
				})
				
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		globalData: {
			test: ''
		},
		methods: {
			...mapMutations(['setUserinfo','setUserPower']),
			 
		   // 从state中拿到数据 箭头函数可使代码更简练
		   username: state => state.username,
						
					
		}
	}
</script>

<style lang="scss">
	@import '@/uni_modules/uni-scss/index.scss';
	/* #ifndef APP-PLUS-NVUE */
	/* uni.css - 通用组件、模板样式库，可以当作一套ui库应用 */
	@import './common/uni.css';
	@import '@/static/customicons.css';
	/* H5 兼容 pc 所需 */
	/* #ifdef H5 */
	@media screen and (min-width: 768px) {
		body {
			overflow-y: scroll;
		}
	}

	/* 顶栏通栏样式 */
	/* .uni-top-window {
	    left: 0;
	    right: 0;
	} */

	uni-page-body {
		background-color: #F5F5F5 !important;
		min-height: 100% !important;
		height: auto !important;
	}

	.uni-top-window uni-tabbar .uni-tabbar {
		background-color: #fff !important;
	}

	.uni-app--showleftwindow .hideOnPc {
		display: none !important;
	}

	/* #endif */

	/* 以下样式用于 hello uni-app 演示所需 */
	page {
		background-color: #efeff4;
		height: 100%;
		font-size: 28rpx;
		/* line-height: 1.8; */
	}

	.fix-pc-padding {
		padding: 0 50px;
	}

	.uni-header-logo {
		padding: 30rpx;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 10rpx;
	}

	.uni-header-image {
		width: 100px;
		height: 100px;
	}

	.uni-hello-text {
		color: #7A7E83;
	}

	.uni-hello-addfile {
		text-align: center;
		line-height: 300rpx;
		background: #FFF;
		padding: 50rpx;
		margin-top: 10px;
		font-size: 38rpx;
		color: #808080;
	}

	/* #endif*/
</style>
